<?php
/**
 * Created by PhpStorm.
 * User: 89511
 * Date: 2018/10/18
 * Time: 14:31
 */

namespace app\index\controller;

use think\Controller;
use think\Db;

class Apiforother
{
    // 数据统计接口 返回 商户、门店、收银员、终端 总数
    public function data_statistics()
    {
        $partners_and_tools = Db::name('partners_and_tools');
        $data = $partners_and_tools->where("id=1")->field('store_num,merchant_num,cashier_num,terminal_num,time,man_num,men_num')->find();
        $today = date("Y-m-d", time());
        if ($data['time'] < $today) {
            $data['store_num'] = (string)(round($data['store_num'] * 1) + rand(500, 1000));
            $data['merchant_num'] = (string)round($data['store_num'] / 2.6);
            $data['cashier_num'] = (string)round($data['store_num'] * 2.8);
            $data['terminal_num'] = (string)round($data['cashier_num'] * 1.2);
            $data['man_num'] = (string)round($data['cashier_num'] / 3.2);//男收银员数量
            $data['men_num'] = (string)($data['cashier_num'] * 1 - $data['man_num'] * 1);//女收银员数量
            $data['time'] = (string)($today);
            $partners_and_tools->where("id=1")->update($data);
        }
        return json_encode($data);
    }

    // 返回今日交易总额
    public function today_total_volume()
    {
        $trading_sum_today = Db::name('trading_sum_today');
        $time = date('Y-m-d', time());
        $res = $trading_sum_today->where("time='{$time}'")->select();
        return $res[0]['trading_sum_today'];
    }
}